using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.UserDomain;
//using ShivamEMR.Web.Areas.User.Models;
using ShivamEMR.Model.DataInterfaces.UsersDataInterf;
using ShivamEMR.Model;
using ShivamEMR.Web.Models;

namespace ShivamEMR.Web.Areas.User.Controllers
{   
    public class UserTaskController : Controller
    {
		private readonly IUserTaskRepository usertaskRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public UserTaskController()  
        {
            usertaskRepository = Registry.RepositoryFactory.GetUserTaskRepository();
        }

        public UserTaskController(IUserTaskRepository usertaskRepository)
        {
			this.usertaskRepository = usertaskRepository;
        }

        //
        // GET: /UserTask/
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Index()
        {
           // return View(usertaskRepository.AllIncluding(usertask => usertask.UserLogs));
            return View(usertaskRepository.All);
        }

        //
        // GET: /UserTask/Details/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Details(int id)
        {
            return View(usertaskRepository.Find(id));
        }

        //
        // GET: /UserTask/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /UserTask/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Create(UserTask usertask)
        {
            if (ModelState.IsValid) {
                usertaskRepository.Create(usertask);
                usertaskRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /UserTask/Edit/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Edit(int id)
        {
             return View(usertaskRepository.Find(id));
        }

        //
        // POST: /UserTask/Edit/5

        [HttpPost]
        public ActionResult Edit(UserTask usertask)
        {
            if (ModelState.IsValid) {
                usertaskRepository.Update(usertask);
                usertaskRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /UserTask/Delete/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Delete(int id)
        {
            return View(usertaskRepository.Find(id));
        }

        //
        // POST: /UserTask/Delete/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            //usertaskRepository.Delete(id);
            var task = usertaskRepository.Find(id);
            usertaskRepository.Delete(task);
            usertaskRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

